﻿Imports System.IO
Imports System.Windows.Forms
Imports Model.Project
Imports Model.Result

Public Class PATHHelper
    Public Shared Sub createPro(ByRef newpro As MyProject)
        Directory.CreateDirectory(newpro.ProDir + "\" + newpro.ProID + newpro.ProName)
        Directory.CreateDirectory(newpro.ProDir + "\" + newpro.ProID + newpro.ProName + "\" + "pointcloud")
        Directory.CreateDirectory(newpro.ProDir + "\" + newpro.ProID + newpro.ProName + "\" + "midline")
        Directory.CreateDirectory(newpro.ProDir + "\" + newpro.ProID + newpro.ProName + "\" + "result")
    End Sub
    ''' <summary>
    ''' 将当前工程信息添加到目录树
    ''' </summary>
    ''' <param name="trv"></param>
    ''' <param name="newpro"></param>
    ''' <remarks></remarks>
    Public Shared Sub setTreeView(ByRef trv As TreeView, ByRef newpro As MyProject)
        trv.Nodes.Clear()
        trv.Nodes.Add("project", newpro.ProID + newpro.ProName)
        trv.Nodes("project").Tag = "root"
        trv.Nodes(0).Nodes.Add("midline", "中线数据").Tag = "first"
        trv.Nodes(0).Nodes.Add("pointcloud", "点云数据").Tag = "second"
        trv.Nodes(0).Nodes.Add("result", "成果数据").Tag = "third"
        trv.Nodes(0).Nodes("midline").Nodes.Add("隧道中线（平）.txt").Tag = "childline"
        trv.Nodes(0).Nodes("midline").Nodes.Add("隧道中线（竖）.txt").Tag = "childline"
        For i = 0 To newpro.ProPts.Count - 1
            trv.Nodes(0).Nodes("pointcloud").Nodes.Add(Path.GetFileName(newpro.ProPts(i))).Tag = "childpt"
        Next
        'trv.Nodes(0).Nodes("result").Nodes.Add("fileofcad", "CAD图")
        'trv.Nodes(0).Nodes("result").Nodes.Add("fileofexcel", "检测报表")
        'trv.Nodes(0).Nodes("result").Nodes.Add("fileofsection", "断面文件")
        'trv.Nodes(0).Nodes("result").Nodes(1).Nodes.Add("20180103断面检测成果表.xls")
        trv.ExpandAll()
    End Sub
    ''' <summary>
    ''' 增加点云文件到目录树
    ''' </summary>
    ''' <param name="trv"></param>
    ''' <param name="name"></param>
    ''' <remarks></remarks>
    Public Shared Sub addptTreeView(ByRef trv As TreeView, ByRef name As String)
        Dim filename = Path.GetFileName(name)
        trv.Nodes(0).Nodes("pointcloud").Nodes.Add(filename)
    End Sub
    ''' <summary>
    ''' 将处理结果加载到工程目录树中
    ''' </summary>
    ''' <param name="trv"></param>
    ''' <param name="results">结果集</param>
    ''' <param name="makeExcel">是否生成检测成果表</param>
    ''' <param name="makeCad">是否绘制cad图</param>
    ''' <param name="timenow" >当前时间</param>
    ''' <remarks></remarks>
    Public Shared Sub addResultTreeView(ByRef trv As TreeView, ByRef results As List(Of CircleResult), ByRef makeExcel As Boolean, ByRef makeCad As Boolean, ByRef timenow As String)
        Dim noderesult = trv.Nodes("project").Nodes("result")
        Dim nodenow = noderesult.Nodes.Add(timenow, timenow)
        nodenow.Nodes.Add("fileofcad", "CAD图")
        nodenow.Nodes.Add("fileofexcel", "检测报表")
        nodenow.Nodes.Add("fileofsection", "断面文件")
        For i = 0 To results.Count - 1
            results(i).standmil()
            Dim currnode = nodenow.Nodes("fileofsection").Nodes.Add(results(i).stand_mil, results(i).stand_mil)
            currnode.Nodes.Add("datafile", results(i).stand_mil + ".dat")
            currnode.Nodes.Add("detectresult", results(i).stand_mil + "拟合检测结果.txt")
        Next
        If makeExcel = True Then
            nodenow.Nodes("fileofexcel").Nodes.Add(trv.Nodes("project").Text + "断面测量记录表.xls")
        End If
        If makeCad = True Then
            nodenow.Nodes("fileofcad").Nodes.Add(trv.Nodes("project").Text + "断面拟合图.dwg")
        End If
        trv.ExpandAll()
    End Sub

    ''' <summary>
    ''' 将处理结果加载到工程目录树中
    ''' </summary>
    ''' <param name="trv"></param>
    ''' <param name="results">结果集</param>
    ''' <param name="makeExcel">是否生成检测成果表</param>
    ''' <param name="makeCad">是否绘制cad图</param>
    ''' <param name="timenow" >当前时间</param>
    ''' <remarks></remarks>
    Public Shared Sub addResultTreeView(ByRef trv As TreeView, ByRef results As List(Of HorseResult), ByRef makeExcel As Boolean, ByRef makeCad As Boolean, ByRef timenow As String)
        Dim noderesult = trv.Nodes("project").Nodes("result")
        Dim nodenow = noderesult.Nodes.Add(timenow, timenow)
        nodenow.Nodes.Add("fileofcad", "CAD图")
        nodenow.Nodes.Add("fileofexcel", "检测报表")
        nodenow.Nodes.Add("fileofsection", "断面文件")
        For i = 0 To results.Count - 1
            results(i).standmil()
            Dim currnode = nodenow.Nodes("fileofsection").Nodes.Add(results(i).stand_mil, results(i).stand_mil)
            currnode.Nodes.Add("datafile", results(i).stand_mil + ".dat")
            currnode.Nodes.Add("detectresult", results(i).stand_mil + "拟合检测结果.txt")
        Next
        If makeExcel = True Then
            nodenow.Nodes("fileofexcel").Nodes.Add(trv.Nodes("project").Text + "断面测量记录表.xls")
        End If
        If makeCad = True Then
            nodenow.Nodes("fileofcad").Nodes.Add(trv.Nodes("project").Text + "断面拟合图.dwg")
        End If
        trv.ExpandAll()
    End Sub
End Class

